package cn.good.yan.utils;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * Redis的连接
 * @author shengren.yan
 * @create 2023-11-16
 */
public class RedisUtils {
    // redis 连接地址
    public static final String  REDIS_IP_ADDR = "127.0.0.1";
    // redis 连接密码
    public static final String  REDIS_pwd = "111111";
    // redis 连接端口
    public static final Integer  REDIS_post = 6379;
    public static JedisPool jedisPool;

    static {
        JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
        jedisPoolConfig.setMaxTotal(20);
        jedisPoolConfig.setMaxIdle(10);
        jedisPool = new JedisPool(jedisPoolConfig, REDIS_IP_ADDR, REDIS_post, 10000, REDIS_pwd);
    }

    public static Jedis getJedis() throws Exception {
        if(null!=jedisPool){
            return jedisPool.getResource();
        }
        throw new Exception("Jedispool is not ok");
    }

}
